package com.yaorange.nongjt.certificate.service.impl;

import java.util.List;

import com.yaorange.nongjt.certificate.domain.NjtUserRegister;
import com.yaorange.nongjt.certificate.mapper.NjtUserRegisterMapper;
import com.yaorange.nongjt.common.enums.YesOrNoEnum;
import com.yaorange.nongjt.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yaorange.nongjt.certificate.mapper.NjtUserPerfectMapper;
import com.yaorange.nongjt.certificate.domain.NjtUserPerfect;
import com.yaorange.nongjt.certificate.service.INjtUserPerfectService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户完善信息Service业务层处理
 *
 * @author coach tam
 * @date 2024-10-12
 */
@Service
public class NjtUserPerfectServiceImpl implements INjtUserPerfectService
{
    @Autowired
    private NjtUserPerfectMapper njtUserPerfectMapper;
    @Autowired
    private NjtUserRegisterMapper njtUserRegisterMapper;
    /**
     * 查询用户完善信息
     *
     * @param id 用户完善信息主键
     * @return 用户完善信息
     */
    @Override
    public NjtUserPerfect selectNjtUserPerfectById(Long id)
    {
        return njtUserPerfectMapper.selectNjtUserPerfectById(id);
    }

    /**
     * 查询用户完善信息列表
     *
     * @param njtUserPerfect 用户完善信息
     * @return 用户完善信息
     */
    @Override
    public List<NjtUserPerfect> selectNjtUserPerfectList(NjtUserPerfect njtUserPerfect)
    {
        return njtUserPerfectMapper.selectNjtUserPerfectList(njtUserPerfect);
    }

    /**
     * 新增用户完善信息
     *
     * @param njtUserPerfect 用户完善信息
     * @return 结果
     */
    @Override
    public int insertNjtUserPerfect(NjtUserPerfect njtUserPerfect)
    {
        njtUserPerfect.setCreateTime(DateUtils.getNowDate());
        return njtUserPerfectMapper.insertNjtUserPerfect(njtUserPerfect);
    }

    /**
     * 修改用户完善信息
     *
     * @param njtUserPerfect 用户完善信息
     * @return 结果
     */
    @Override
    public int updateNjtUserPerfect(NjtUserPerfect njtUserPerfect)
    {
        njtUserPerfect.setUpdateTime(DateUtils.getNowDate());
        return njtUserPerfectMapper.updateNjtUserPerfect(njtUserPerfect);
    }

    /**
     * 批量删除用户完善信息
     *
     * @param ids 需要删除的用户完善信息主键
     * @return 结果
     */
    @Override
    public int deleteNjtUserPerfectByIds(Long[] ids)
    {
        return njtUserPerfectMapper.deleteNjtUserPerfectByIds(ids);
    }

    /**
     * 删除用户完善信息信息
     *
     * @param id 用户完善信息主键
     * @return 结果
     */
    @Override
    public int deleteNjtUserPerfectById(Long id)
    {
        return njtUserPerfectMapper.deleteNjtUserPerfectById(id);
    }

    @Override
    @Transactional
    public int audit(NjtUserPerfect njtUserPerfect) {
        //更新注册表中的会员标记
        NjtUserRegister njtUserRegister = new NjtUserRegister();
        njtUserRegister.setId(njtUserPerfect.getId());
        njtUserRegister.setMemberFlag(YesOrNoEnum.YES.CODE);
        njtUserRegisterMapper.updateNjtUserRegister(njtUserRegister);

        return njtUserPerfectMapper.audit(njtUserPerfect);
    }

    /**
     * 根据用户注册id查询会员完善信息
     *
     * @param userId
     * @return
     */
    @Override
    public NjtUserPerfect getByRegisterUserId(Long userId) {
        return njtUserPerfectMapper.selectNjtUserPerfectById(userId);
    }
}
